<?php
	class Conf extends MY_Model {
		function __construct(){
			parent::__construct();
			$this->load->library('tree');
		}
		
		function get_config_tree($key = ''){
			$k = trim($key);
			$this->db->select('*');
			$this->db->from('conf');
			$query = $this->db->get('');
			$lists = ($query->result_array());
			$tree = $this->tree->toTree($lists, 'id','parent','_child');
			if($k){
				//查找是否包含当前key
				$this->db->select('*');
				$this->db->from('conf');
				$this->db->where('key',$k);
				$this->db->where('parent',0);
				if($this->db->get('')->result_array()){
					//反悔回当前级别配置
					foreach($tree as $kt => $vt){
						if($vt['key'] == $k)$data = $tree[$kt];
					}
					if(isset($data['_child'])){
						$obj = array();
						foreach($data['_child'] as $kc => $vc)
							$obj[$vc['key']] = $vc['value'];
					}else $obj[$data['key']] = $data['value'];
					return (Object)$obj;
				}else return false;
			}else return $this->tree->toFormatTree($lists,'key','id','parent',0);
		}
	}